<?php

// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件

function bili($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $contents = curl_exec($ch);
    $a = json_decode($contents);
    if ($a == []) {
        $as = cookie("think_var");
        if ($as == 'zh-cn') {
            $bili = "出错了，暂时无法获取！";
        } else {
            $bili = "Error, temporarily unavailable!";
        }


        return $bili;
    } else {
        //$bili = "41";
        $amount = $a[3]->amount;
        $price = $a[3]->price;
        $bili = $amount / $price;
    }

    return round($bili, 2);
}

function left() {
    //$this->assign("name", "2");
    $rid = session("u_rid"); //取出用户权限ID
    $onelist = "";
    $twolist = "";
    //根据用户ID找出权限ID
    if ($rid == 1) {
        //总管理员 查询所有
        $onelist = db("auth")->where("auth_level=0")->select(); //一级菜单

        $twolist = db("auth")->where("auth_level=1")->select(); //二级菜单
        $this->assign('onelist', $onelist);
        $this->assign('twolist', $twolist);
    } else {

        $u_menu = db("role")->where("r_id=$rid")->value("r_menu"); //用户对应权限

        $onelist = db('auth')->where("auth_pid=0 and auth_id in ($u_menu)")->select(); //一级菜单
        $twolist = db('auth')->where("auth_pid!=0 and auth_id in ($u_menu)")->select(); //二级菜单
        $this->assign('onelist', $onelist);
        $this->assign('twolist', $twolist);
    }

    return $this->fetch("public/left");
}
